'use strict';
	angular.module('accounting.profitLossQueryList', [])

	.controller('profitLossQueryListCtrl',['$rootScope', '$scope', 'BizData', 'systemService', f])
    function f($rootScope, $scope, BizData, systemService) {

		var Model = this;
		
		//修改
		Model.edit = function(){
			Model.dataMaster.editData();
		};
		
		//保存
		Model.save = function() {
			Model.dataMaster.saveData();
		};

		//取消编辑
		Model.saveCancel = function() {
			Model.dataMaster.editCancel();
		};

		
		Model.grid_carriedNoButtonClick = function(){
			
			var dataMaster = Model.dataMaster;
			var rowID = dataMaster.getCurrentID();
			var enterpriseNo = dataMaster.getValue('enterpriseNo',rowID);

			var options = {};
			
			options.recordState = 'none';
			options.id = enterpriseNo;

			var modalInstance = systemService.openCaptionNoDialog(options);

	        //模态窗口关闭之后执行的事件
	        modalInstance.result.then(function (event) {  
	             //成功关闭窗口
	         	var returnData = event.data;
     			dataMaster.setValue('carriedNo', returnData[0].captionNo, rowID);
     			dataMaster.setValue('carriedName', returnData[0].captionName, rowID);

	        }, function (reason) {  
	            console.info('Modal dismissed at: ' + new Date());  
	        });  
		};
		
		
		
		
		
		
		var options = {};
		options.container = Model;
		options.concept = 'AccountCaption';
		options.name = 'dataMaster';
		options.url = $rootScope.path;
		options.httpUrl = $rootScope.getServiceName();
		options.reader = '/accounting/profitLoss/list/query';
		options.writer = '/accounting/profitLoss/list/save';
		options.deleter = '';
		options.idColumnDefine = "fID";
		options.idColumnName = "fID";
		options.isTree = false;
		options.parentRelation = 'fParent';
		options.nodeKindRelation = 'nodeKind';
		options.nodeLevelRelation = 'nodeLevel';
		options.pathRelation = '';
		options.master = {"data":"","relation":""};
		options.directDeleteMode = false;
		options.orderBy = 'captionNo ASC';
		options.limit = 500;

		Model.dataMaster = new BizData(options);

		//监视对象中的所有变动
		Model.dataMaster.deregRows = $scope.$watch('Model.dataMaster.rows',Model.dataMaster.watchRows,true);//true代表深度监视，包括对象的属性，而不是简单的一个值
		//////////////////////////////////////////////

		//设置过滤条件
		Model.dataMaster.filter = " AccountCaption.billType='SYKM' "
			+ " AND AccountCaption.nodeKind='nkLeaf'"
			
			;

		//刷新数据
		Model.dataMaster.refreshData();
		////////////////////启动执行结束///////////////////////////////////////////////////
	    
		Model.refresh = function(){
			Model.dataMaster.refreshData();
		}
	    
		Model.query = function(){
			Model.dataMaster.queryData();
		}

		Model.filters = [];
		
	    return Model;
		
	}	
	
